Skip to content

查找文字 - FindStr

函数简介

查找指定文字的坐标,返回相对绑定窗口坐标,返回最优坐标。成功时返回 str| 分割后的关键字索引(从 0 开始),屏幕上未找到返回 -1dict / str 有一段可用就继续;全部字库加载不到返回 -9001,全部文字拼不出返回 -9002。详见 字库找字错误码说明

接口名称

FindStr

DLL调用

int FindStr(long ola, int x1, int y1, int x2, int y2, string str, string colorList, string dict, double matchVal, int* outX, int* outY);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
x1整数型查找区域的左上角X坐标。
y1整数型查找区域的左上角Y坐标。
x2整数型查找区域的右下角X坐标。
y2整数型查找区域的右下角Y坐标。
str字符串待查找的字符串,可以是字符串组合,比如 "str1|str2|str3"有一段能拼就继续找字;全部都拼不出才失败(9002)。GetLastErrorString 会带上缺失文字,便于核对中文编码
colorList字符串颜色模型配置字符串,用于限定图像匹配中的颜色范围,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:3278FA-000000|6496FF-2020203278FA~6496FFFF0000|00FF00
dict字符串字库名称,为空时搜索所有已加载字库;多个字库用 | 分割,如 dict1|dict2有一段能加载就继续;全部加载不到才失败(9001)
matchVal双精度浮点数相似度,如 0.85,最大为 1。
outX整数型指针输出参数,返回的X坐标。
outY整数型指针输出参数,返回的Y坐标。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
int32_t outX = 0, outY = 0;
int ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, &outX, &outY);
if (ret >= 0) {
    // ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
int ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, out int outX, out int outY);
if (ret >= 0)
{
    // ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# 0,0,0,0 表示绑定窗口整个客户区
ret, outX, outY = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9)
if ret >= 0:
    pass  # ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.ApiResult;
import com.olaplug.model.Point;
import com.olaplug.model.MatchResult;
import java.util.List;

OLAPlugServer ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
ApiResult<Point> result = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9);
if (result != null && result.success) {
    int outX = result.data.X;
    int outY = result.data.Y;
    // result 成功时 ret/index 为关键字索引(从 0 开始)
}
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// 0,0,0,0 表示绑定窗口整个客户区
var outX, outY int32
ret := ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, &outX, &outY)
if ret >= 0 {
    // ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
}
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// 0,0,0,0 表示绑定窗口整个客户区
let mut out_x: i32 = 0;
let mut out_y: i32 = 0;
let ret = ola.find_str(0, 0, 0, 0, "确定", "000000", "", 0.9, &mut out_x, &mut out_y);
if ret >= 0 {
    // ret 为关键字索引(从 0 开始),out_x/out_y 为匹配坐标
}
cpp
var ola = com("OlaPlug.OlaSoft")
// 0,0,0,0 表示绑定窗口整个客户区
var outX = 0
var outY = 0
var ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, outX, outY)
if(ret >= 0) {
    // ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 0,0,0,0 表示绑定窗口整个客户区
Dim outX, outY
ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, outX, outY)
If ret >= 0 Then
    ' ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
End If
text
.局部变量 ola, OLAPlug
ola.Create ()
' 0,0,0,0 表示绑定窗口整个客户区
.局部变量 outX, 整数型
.局部变量 outY, 整数型
.局部变量 ret, 整数型
ret = ola.FindStr(0, 0, 0, 0, “确定“, “000000“, ““, 0.9, outX, outY)
.如果真 (ret ≥ 0)
    ' ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var outX = 0;
var outY = 0;
var ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, outX, outY);
if(ret >= 0){
    // ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 0,0,0,0 表示绑定窗口整个客户区
整数类 outX
整数类 outY
整数 ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, outX, outY)
如果真 (ret >= 0)
    // ret 为关键字索引(从 0 开始),outX.值/outY.值 为匹配坐标
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
int32_t outX = 0, outY = 0;
int32_t ret = ola.FindStr(0, 0, 0, 0, "确定", "000000", "", 0.9, &outX, &outY);
if (ret >= 0) {
    // ret 为关键字索引(从 0 开始),outX/outY 为匹配坐标
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
int outX = 0, outY = 0;
int ret = FindStr(instance, 0, 0, 0, 0, "确定", "000000", "", 0.9, &outX, &outY);
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FindStr(long ola, int x1, int y1, int x2, int y2, string str, string colorList, string dict, double matchVal, out int outX, out int outY);

long instance = CreateCOLAPlugInterFace();
int ret = FindStr(instance, 0, 0, 0, 0, "确定", "000000", "", 0.9, out int outX, out int outY);
python
from ctypes import CDLL, c_int, c_int64, c_double, c_char_p, POINTER, byref

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ola.FindStr.argtypes = [c_int64, c_int, c_int, c_int, c_int, c_char_p, c_char_p, c_char_p, c_double, POINTER(c_int), POINTER(c_int)]
ola.FindStr.restype = c_int
instance = ola.CreateCOLAPlugInterFace()
out_x = c_int(0)
out_y = c_int(0)
ret = ola.FindStr(instance, 0, 0, 0, 0, b"确定", b"000000", b"", 0.9, byref(out_x), byref(out_y))

返回值

返回值说明
>=0成功。返回值为 str| 分割后命中关键字的索引(从 0 开始)。例如查找 "确定|取消" 命中“取消”时返回 1
-1屏幕上未找到(字库与文字均已通过校验)。
-9001全部指定字库都加载不到(GetLastError()9001)。
-9002全部查找文字都无法用字库拼出(GetLastError()9002)。

失败时请立即调用 GetLastError / GetLastErrorString9002 的字符串会原样带上缺失文字(如 字库中找不到指定文字(你好));若这里是乱码,说明入参编码与 SetDefaultEncode 不一致。完整对照见 字库找字错误码说明